/***************************************************************
 * Name:      bonusApp.cpp
 * Purpose:   Code for Application Class
 * Author:    William Wang ()
 * Created:   2009-06-23
 * Copyright: William Wang ()
 * License:
 **************************************************************/
//#define 	wxDISABLE_DEBUG_SUPPORT()
 #define USE_WXMSW 1
 #include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "global.h"
#include "bonusApp.h"
#include "bonusMain.h"
#include <wx/file.h>


#include <wx/xrc/xmlres.h>
#include <wx/statbmp.h>
#include "../testMain/resource.h"
#include <windows.h>

#include <wx/msgdlg.h>

//DECLARE_APP(bonusApp);
IMPLEMENT_APP(bonusApp);

bonusFrame* BFrame=NULL;
 bool  __DEBUG=false;
 int GRID_ROW=-1;
 int GRID_COL=-1;

bool bonusApp::OnInit()
{

//  MessageBox (NULL, _("Hello"), _("Hello Demo"), MB_OK);
//find program argument
if(this->argc>1)
{
 wxString argument;
 for(int i=1;i<this->argc;i++)
 {
  argument=wxString(this->argv[i]).Upper();
  if(argument.Find(wxT("DEBUG"))!=wxNOT_FOUND)__DEBUG=true;
  if(argument.Find(wxT("HELP"))!=wxNOT_FOUND)
    wxMessageBox(_("命令行参数:\n DEBUG打开系统调试!"));
  }

}
//  MessageBox (NULL, _("Hello"), _("Hello 62"), MB_OK);
if(__DEBUG)wxMessageBox(_("程序打开了DEBUG模式!!!"));
    wxInitAllImageHandlers();
    wxXmlResource::Get()->InitAllHandlers();
    wxSocketBase::Initialize() ;
    InitXmlResource();
    checkDatabase();
    DoubleBall* db= new DoubleBall();
    db->initialize();//
    delete db;
//必须在初始化之前

//   bonusFrame::moneypig  = wxXmlResource::Get()->LoadBitmap(_T("moneypigIco"));
   //bonusFrame::money  = wxXmlResource::Get()->LoadBitmap(_T("moneyIco"));

   bonusFrame::appIcon = wxXmlResource::Get()->LoadIcon(_T("appIco"));

    if(!bonusFrame::appIcon.IsOk())
       {
           wxMessageBox(_("Not find appIcon"));
       }
//    if(!bonusFrame::moneypig.IsOk())
//       {
//           wxMessageBox(_("Not find moneypig "));
//       }
//    if(!bonusFrame::money.IsOk())
//       {
//           wxMessageBox(_("Not find money "));
//       }
//
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    wxXmlResource::Get()->InitAllHandlers();
    wxsOK = wxsOK && wxXmlResource::Get()->Load(_T("redballDialog.xrc"));
    if ( wxsOK )
    {
    	bonusFrame* Frame = new bonusFrame(0);
    	Frame->Show();
    	SetTopWindow(Frame);
    }
    //*)

    BFrame->SetIcon(BFrame->appIcon);
   	BFrame->Show();


  // 	SetTopWindow(BFrame);

    return true;//wxsOK;

}

//全局热键处理入口
int bonusApp::FilterEvent(wxEvent& event)
{
    if ( event.GetEventType()==wxEVT_KEY_DOWN )
    {
       switch(((wxKeyEvent&)event).GetKeyCode())
        {
         case WXK_F2:
         case WXK_F3:
         case WXK_F4:
         case WXK_F5:
         case WXK_F6:
         case WXK_F7:
         case WXK_F8:
         case WXK_F9:
         case WXK_F10:
           {
            BFrame->OnKeyDown( (wxKeyEvent&)event );
              return true;
          }
        }
        //conbination key
       if(((wxKeyEvent&)event).GetModifiers()==wxMOD_CONTROL)// && BFrame->Grid1!=NULL
        {
            switch(((wxKeyEvent&)event).GetKeyCode())
           {
            case 'w':
            case 'W'://剪贴数据_T("F1:Help<p>")

            case 's':
            case 'S'://保存预测
            case 'd': //显示是否刷新grid的空白部分
            case 'D':
            case 'g':
            case 'G'://调到指定期
            case 'l'://显示相似记录
            case 'L':
            case 'q':
            case 'Q':
            case 'p':
            case 'P'://print grid
            case 'R':
            case 'r'://统计最近5期出现的红球
            case 'H':
            case 'h'://Save to HTML


//            wxMessageBox(getLastTermOrder()+_("\n")+getLastTermDate());
            BFrame->OnKeyDown( (wxKeyEvent&)event );
                          return true;
           }
        }
        event.Skip();
    }
    return -1;
}
 int bonusApp::OnExit()
 {

 }
